package com.service.impl;

import com.common.constant.MailConstant;
import com.common.constant.SharesConstan;
import com.common.utils.DateUtil;
import com.common.utils.MeUtils;
import com.common.utils.StringUtil;
import com.entity.CodeCjl;
import com.entity.HintCode;
import com.entity.SharesDetail;
import com.entity.SharesUnfasten;
import com.mapper.HintCodeMapper;
import com.service.CodeCjlService;
import com.service.HintCodeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wty
 * @since 2021-10-26
 */
@Service
public class HintCodeServiceImpl extends ServiceImpl<HintCodeMapper, HintCode> implements HintCodeService {


    @Autowired
    private CodeCjlService codeCjlService;
    /**
     *
     * @param parse
     * @param szorsh
     * @param hintCode
     * @return
     */
    @Override
    public String getzf(List<Object> parse, String szorsh, HintCode hintCode) {
        DecimalFormat df = new DecimalFormat("0.00");
        String time = hintCode.getTime();
        BigDecimal tsPrice = hintCode.getTsPrice();

        if(CollectionUtils.isEmpty(parse)){
            return null;
        }
        String zdf="";
        for (Object o : parse) {

            String[] splito = o.toString().split(",");
            if(splito[0].equals(time)){
                BigDecimal zcjl = new BigDecimal(splito[5]);
                BigDecimal spj = new BigDecimal(splito[2]);//收盘价
                BigDecimal kpj = new BigDecimal(splito[1]);//开盘价
                BigDecimal bigDecimal = MeUtils.calculateTrend( splito[2],tsPrice.toString());
                zdf=bigDecimal.toString();
                break;
            }
        }
        String format = df.format(Double.valueOf(zdf.toString()));

        return  format;
    }

    private Map<String,String> getMaxBackStr(HintCode codeCjl) {
        CodeCjl vo1 = SharesConstan.CODE_MAP.get(codeCjl.getCode());
        StringBuffer sb=new StringBuffer(vo1.getZzf());

        String zyback="";
        if(!StringUtil.isEmpty(vo1.getZyback())){
            BigDecimal zbig = MeUtils.calculateTrend(codeCjl.getTsPrice().toString()
                    , vo1.getZyback().split("-")[0]);
            BigDecimal ybig = MeUtils.calculateTrend(codeCjl.getTsPrice().toString()
                    , vo1.getZyback().split("-")[1]);
            sb.append("\n"+"近一周回撤风险"+MeUtils.getPercent(zbig.toEngineeringString()));
            sb.append("\n"+"近一月回撤风险"+MeUtils.getPercent(ybig.toEngineeringString()));
            zyback=""+MeUtils.getPercent(zbig.toEngineeringString())+"---"
                    +MeUtils.getPercent(ybig.toEngineeringString());
        }
        Map<String,String> map=new HashMap<>();
        map.put("sb",sb.toString());
        map.put("zyback",zyback);
        return map;
    }
}
